<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.min.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.easyui.min.js"></script>
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/icon.css" />
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/black/easyui.css" />
<script type="text/javascript" src="js/common.js"></script>
<title>订单明细</title>
</head>
<body>
	<style type="text/css">
.step {
	margin-top: 20px;
}
</style>
	<script type="text/javascript">
		function deleteOrderDetails(coId) {
			$.messager.confirm('提示', '确定要删除吗？', function(v) {
				if (v) {
					$.getJSON('deleteOd', {
						odId : coId
					}, function(obj) {
						if (obj.success) {
							$('#zj-orderDetails-datagrid').datagrid('reload');
						} else {
							$.messager.alert('提示', '操作失败, 原因：' + obj.message);
						}
					});
				}
			});
		}

		/* function editOrderDetails(odId) {
			$("#zj-orderDetails-dg").dialog({
				title : '编辑订单明细',
				href2 : 'editOrderDetails'
			});
			var row = $("#zj-orderDetails-datagrid").datagrid('getSelected');
			$("#zj-orderDetails-form").form('load', 'getodById?odId=' + odId);
			$("#zj-orderDetails-form-cus").textbox({readonly:true});
			$('#zj-input-order-zj').textbox("setText",row.coThemezj);
			$("#zj-orderDetails-dg").dialog("open");
		} */

		$(function() {
			$("#zj_btn_orderDetails_add").linkbutton({
				onClick : function() {
					$("#zj-orderDetails-dg").dialog({
						href2 : "addNewOrderDetails",
						title : "新建订单明细"
					});
					$("#zj-orderDetails-form-cus").textbox({readonly:false});
					$("#zj-orderDetails-form").form("clear");
					$("#zj-orderDetails-dg").dialog("open");
				}
			});

			$("#zj-od-brid").textbox({
				onChange : function() {
					var coId = $('#zj-od-brid').textbox('getValue');
					$('#zj-input-order-zj').combobox({
						url : 'getOrdersById?coId=' + coId,
						valueField : 'coId',
						textField : 'coTheme'
					});
				}
			});

			$('#zj-input-order-zj').combobox({
				onSelect : function(oo) {
					$('#zj-od-brid2').textbox('setValue', oo.coId);
				}
			});

			$('#zj-input-order-pro').combobox({
				onSelect : function(oo) {
					$('#zj-od-brid3').textbox('setValue', oo.productId);
				}
			});

			$("#zj-od-brid2").textbox({
				onChange : function() {
					var oid = $("#zj-od-brid2").textbox("getValue");
					$("#zj-input-order-pro").combobox({
						url : 'getProductByOid?oid=' + oid,
						valueField : 'productId',
						textField : 'productName'
					});
				}
			});

			$("#zj_orderDetails_list_all").linkbutton({
				onClick : function() {
					$("#zj-orderDetails-datagrid").datagrid({
						pageNumber : 1,
						url : 'getAllOrderDetails'
					});
					$("#zj-orderDetails-datagrid").datagrid("reload");
				}
			});

			$("#zj_cut_order_details_some")
					.linkbutton(
							{
								onClick : function() {
									var rows = $("#zj-orderDetails-datagrid")
											.datagrid('getSelections');
									if (rows.length == 0) {
										$.messager.alert("提示", "请至少选择一行数据！");
										return false;
									}
									var ids = [];
									for (var i = 0; i < rows.length; i++) {
										var id = rows[i].odId;
										ids.push(id);
									}
									if ($.messager
											.confirm(
													'提示',
													'确定要删除选定的订单明细吗？',
													function(v) {
														if (v) {
															$
																	.getJSON(
																			'deleteSomeDetails',
																			{
																				"array[]" : ids,
																			},
																			function(
																					obj) {
																				if (obj.success) {
																					alert("ss")
																					$(
																							'#zj-orderDetails-datagrid')
																							.datagrid(
																									'reload');
																				} else {
																					$.messager
																							.alert(
																									'提示',
																									'操作失败, 原因：'
																											+ obj.message);
																				}
																			});
														}
													}))
										;
								}
							})

			$("#zj-orderDetails-datagrid")
					.datagrid(
							{
								fit : true,
								border : false,
								toolbar : '#zj-orderDetails-tb',
								pageSize : 8,
								pageList : [ 5, 6, 7, 8, 9, 10, 20 ],
								fitColumns : true,
								url : 'getAllOrderDetails',
								method : 'get',
								singleSelect : false,
								pagination : true,
								columns : [ [
										{
											field : 'cc',
											width : 1,
											checkbox : true
										},
										{
											field : 'odId',
											title : 'ID',
											width : 1
										},
										{
											field : 'customerVO',
											title : '对应客户',
											width : 2,
											formatter : function(value, row,
													index) {
												if (value) {
													return value.custName;
												} else {
													return '/';
												}
											}
										},
										{
											field : 'coThemezj',
											title : '订单',
											width : 3,
										},
										{
											field : 'odProName',
											title : '产品',
											width : 2,

										},
										{
											field : 'odProType',
											title : '产品类别',
											width : 2
										},
										{
											field : 'odRemarks',
											title : '产品单位',
											width : 2
										},
										{
											field : 'odPrice',
											title : '单价',
											width : 2
										},
										{
											field : 'odNumber',
											title : '订单数量',
											width : 3
										},
										{
											field : 'odPlanTime',
											title : '计划交付日期',
											width : 3,
											formatter : function(value, row,
													index) {
												if (value) {
													var date = new Date(value);
													var y = date.getFullYear();
													var m = date.getMonth() + 1;
													var d = date.getDate();
													return y + '-' + m + '-'
															+ d;
												}
											}
										},
										{
											field : 'odOwner',
											title : '所有者',
											width : 2
										},
										{
											field : 'bb',
											width : 4,
											title : '操作',
											formatter : function(value, row,
													index) {
												var btn = '<a class="zj-orderDetails-edit" onclick="editOrderDetails('
														+ row.odId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												var btn2 = '<a class="zj-orderDetails-delete" onclick="deleteOrderDetails('
														+ row.odId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												return btn + btn2;
											}
										} ] ],
								onLoadSuccess : function(data) {
									$('.zj-orderDetails-delete').linkbutton({
										text : '删除',
										plain : true,
										iconCls : 'icon-cut'
									});
									/* $('.zj-orderDetails-edit').linkbutton({
										text : '编辑',
										plain : true,
										iconCls : 'icon-edit'
									}); */
								}
							});
		});
	</script>
	<table id="zj-orderDetails-datagrid" class="easyui-datagrid">
	</table>
	<div id="zj-orderDetails-tb">

		<!-- <input class="easyui-searchbox" id="zj-order-theme"
			data-options="width:250,label:'主题：',labelWidth:55,searcher:function(value,name){
				$('#zj-order-dg').datagrid({pageNumber:1, url: 'getOrderByTheme'});
				//重新加载数据
				$('#zj-order-dg').datagrid('load', {coTheme: value});
			}"> -->

		<a id="zj_btn_orderDetails_add" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">添加</a> <a
			id="zj_orderDetails_list_all" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a> <a
			id="zj_cut_order_details_some" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-remove',plain:true">批量删除</a>
	</div>

	<div id="zj-orderDetails-dg" class="easyui-dialog"
		style="width: 400px; height: 530px;"
		data-options="iconCls:'icon-save',resizable:true,closed:true,modal:true,buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
				var row = $('#zj-orderDetails-datagrid').datagrid('getSelected');
				
				alert($('#zj-orderDetails-dg').dialog('options').href2)
					$('#zj-orderDetails-form').form({
						url:$('#zj-orderDetails-dg').dialog('options').href2,
						method:'post',
						onSubmit:function(params){
							if(row != null){
								params.odId = row.odId;
							}
							return $(this).form('validate');
						},
						success:function(v){
							var obj = eval('('+v+')');
							if(obj.success){
								$('#zj-orderDetails-datagrid').datagrid('reload');
							}else{
							$.messager.alert('提示', '操作失败, 原因：' + obj.message);
							}
							$('#zj-orderDetails-dg').dialog('close');
						}
					}).submit();
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
					$('#zj-orderDetails-dg').dialog('close');
				}
			}]">
		<form id="zj-orderDetails-form" method="post">
			<div class="step">
				<input id="zj-od-brid" class="easyui-textbox" name="cusIdvo">
				<input id="zj-orderDetails-form-cus" name="cusNamevo"
					class="easyui-textbox"
					data-options="editable:false,buttonText:'选择客户',required:true,label:' ', labelWidth:'90', width: 300, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-orderDetails-form-cus').textbox('setValue', row.custId);
							$('#zj-orderDetails-form-cus').textbox('setText', row.custName);
							$('#zj-od-brid').textbox('setValue', row.custId);
						});	
					}">
			</div>

			<div class="step">
				<input id="zj-od-brid2" class="easyui-textbox" name="coIdvo">
				<input id="zj-input-order-zj" name="coThemezj"
					class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',required:true,labelAlign:'right',label:'订单',
					width:250, labelWidth:90">
			</div>


			<div class="step">
				<select id="zj-proType" class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',labelAlign:'right',label:'产品类型',
					width:250, labelWidth:90"
					name="odProType">
					<option disabled selected value=''></option>
					<option value="手机">手机</option>
					<option value="电脑">电脑</option>
					<option value="电视">电视</option>
					<option value="家具">家具</option>
				</select>
			</div>
			<div class="step">
				<select id="zj-txt-odRemarks" class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',labelAlign:'right',label:'产品单位',
					width:250, labelWidth:90"
					name="odRemarks">
					<option disabled selected value=''></option>
					<option value="部">部</option>
					<option value="台">台</option>
					<option value="个">个</option>
					<option value="张">张</option>
				</select>
			</div>
			<div class="step">
				<input id="zj-od-brid3" class="easyui-textbox" name="proId">
				<input id="zj-input-order-pro" class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',labelAlign:'right',required:true,label:'产品',
					width:250, labelWidth:90"
					name="proName">
			</div>

			<div class="step">
				<input class="easyui-numberbox" name="odPrice"
					data-options="min:0,precision:2,labelAlign:'right',required:true,label:'单价',
							width:200, labelWidth:90">
			</div>
			<div class="step">
				<input class="easyui-numberbox" name="odNumber"
					data-options="min:0,precision:0,labelAlign:'right',required:true,label:'数量',
							width:200, labelWidth:90">
			</div>

			<div class="step">
				<input class="easyui-datebox"
					data-options="required:true,labelAlign:'right',label:'交付日期',
					width:300, labelWidth:90"
					name="odPlanTime">
			</div>

			<div class="step">
				<input id="zj-orderDetails-form-owner" name="odOwner"
					class="easyui-textbox"
					data-options="editable:false,buttonText:'所有者',label:' ',labelWidth:'90', width: 300, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-orderDetails-form-owner').textbox('setValue', row.custName);
							$('#zj-orderDetails-form-owner').textbox('setText', row.custName);
						});
					}">
			</div>
		</form>
	</div>
</body>
</html>